/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;
import com.startup.musicstore.app.exceptions.MarketInformationPendingException;
import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.Review;
import com.startup.musicstore.services.PostAlbumRatingsService;
import com.startup.musicstore.services.crud.AlbumCrudService;
import com.startup.musicstore.services.crud.ReviewCrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author linda
 */
@Service("postAlbumRatings")
public class PostAlbumRatingsServiceImpl implements PostAlbumRatingsService{
    @Autowired
    private AlbumCrudService albumCrudService;
    
    @Autowired
    private ReviewCrudService reviewCrudService;

    @Override
    public void PostAlbumRatings(Long AlbumID, int rating) 
    {
        Album album = albumCrudService.findById(AlbumID);
        
        if(album.getMarketingInfo().getStatusOfInformation().equalsIgnoreCase("PENDING"))
        {
            throw new MarketInformationPendingException("Marketing Status is pending");
        }
        else
        {
            
             Review review = album.getMarketingInfo().getReview();
             review.setRating(rating);
             reviewCrudService.merge(review);
        }
      
    }
    
    
}
